- name: prepare setting up the database
  hosts: db01.stg.iad2.fedoraproject.org:db01.iad2.fedoraproject.org
  gather_facts: no
  user: root

  tasks:
  - name: install psycopg2 for the postgresql ansible modules
    package: name=python3-psycopg2 state=present
    tags:
    - packages

- name: setup the database
  hosts: db01.stg.iad2.fedoraproject.org:db01.iad2.fedoraproject.org
  gather_facts: no
  become: yes
  become_user: postgres
  vars_files:
  - /srv/web/infra/ansible/vars/global.yml
  - "/srv/private/ansible/vars.yml"
  - "/srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml"

  tasks:
  - name: Create the database user
    postgresql_user:
      name: "{{ testdays_db_user }}"
      password: "{{ testdays_db_pass }}"
  - name: Create the database itself
    postgresql_db:
      name: "{{ testdays_db_name  }}"
      owner: "{{ testdays_db_user }}"
      encoding: UTF-8
  - name: Test the database creation
    postgresql_db:
      name: "{{ testdays_db_name  }}"
      owner: "{{ testdays_db_user }}"
      encoding: UTF-8
  - name: Create the database user (resultsdb)
    postgresql_user:
      name: "{{ resultsdb_testdays_db_user }}"
      password: "{{ resultsdb_testdays_db_pass }}"
  - name: Create the database itself (resultsdb)
    postgresql_db:
      name: "{{ resultsdb_testdays_db_name  }}"
      owner: "{{ resultsdb_testdays_db_user }}"
      encoding: UTF-8
  - name: Test the database creation (resultsdb)
    postgresql_db:
      name: "{{ resultsdb_testdays_db_name  }}"
      owner: "{{ resultsdb_testdays_db_user }}"
      encoding: UTF-8

- name: make the app be real
  hosts: os_control_stg[0]:os_control[0]
  user: root
  gather_facts: False

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - role: openshift/project
    app: testdays
    description: The Fedora QE testdays application
    appowners:
    - pingou
    - frantisekz
    tags:
      - appowners

  - role: openshift/object
    app: testdays
    template: buildconfig.yml
    objectname: buildconfig.yml

  - role: openshift/object
    app: testdays
    template: deploymentconfig.yml
    objectname: deploymentconfig.yml

  - role: openshift/object
    app: testdays
    template: imagestream.yml
    objectname: imagestream.yml

  - role: openshift/object
    app: testdays
    file: service.yml
    objectname: service.yml

  - role: openshift/route
    app: testdays
    routename: testdays
    host: "testdays{{ env_suffix }}.fedoraproject.org"
    serviceport: 8080-tcp
    servicename: testdays

  - role: openshift/start-build
    app: testdays
    buildname: testdays-build
    objectname: testdays-build
